/**
 * build_project
 * <p>
 * Copyright 2014 cayden.cn, Inc. All rights reserved.
 *
 * @author Administrator
 * @date 2021-09-26 13:35
 */
package com.cayden.config.project.componets.db;

/**
 *
 * @author cayden
 * @date 2021-09-26 13:35
 */
public class DynamicDataSourceHolder {
    public static final ThreadLocal<String> HOLDER = new ThreadLocal<>();
    private static final String MASTER = "master";
    private static final String SLAVE = "slave";

    public static void chooseMaster() {
        HOLDER.set(MASTER);
    }

    public static void chooseSlave() {
        HOLDER.set(SLAVE);
    }

    public static void chooseSlave(int slaveIndex) {
        HOLDER.set(SLAVE + "_" + slaveIndex);
    }

    public static String getDataSouce() {
        return HOLDER.get();
    }

    public static void reset() {
        HOLDER.remove();
    }
}
